#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：zhcx-service-test 
@File    ：remove_public_way.py
@Author  ：关依林
@Date    ：2023/5/10 17:20 
'''

from testcases.Listing_migration.Data_Migration.test_public_way import public_invoking

public_program = public_invoking()

class removeColdData:

    # 获取白名单渠道ID
    def getWhiteListStore(self):
        storeSql = "SELECT OrderSourceID FROM RB_Amazon_Product_Base_ClearColdData(nolock) " \
                   "WHERE AddTime >= '2023-06-01';"
        # storeSql = "SELECT OrderSourceID FROM RB_Amazon_Product_Base_ClearColdData
        # WHERE OrderSourceName IN ('Amazon-Z01489-AU','Amazon-Z01489-CA','Amazon-Z01489-MX','Amazon-Z01489-BR')"
        storeID = public_program.erp_db(storeSql)
        return storeID

    # 获取备份表数据
    def verifyBackupsData(self, orderSourceID):
        erpColdSql = f"SELECT OrderSourceSKUID FROM RB_Amazon_Product_Base_ColdData_Backups(nolock) " \
                     f"WHERE OrderSourceID = {orderSourceID};"
        backupsData = public_program.erp_db(erpColdSql)
        return backupsData

    # 获取热转冷打标表数据
    def getMarkingColdData(self, orderSourceID):
        markingColdSql = f"SELECT OrderSourceSKUID FROM RB_Amazon_Product_Base_ColdHotData(nolock) " \
                         f"WHERE OrdersourceID = {orderSourceID} AND IsHotData = 0 AND AddTime <= '2023-06-01';"
        markingColdData = public_program.erp_db(markingColdSql)
        return markingColdData

    # 获取冷库冷数据库
    def getColdBaseData(self, orderSourceID, OrderSourceSKUID):
        # 先判断渠道所在部门表
        departmentSql = f"SELECT DepartmentId FROM aml_department_ordersource WHERE OrderSourceID = {orderSourceID};"
        departmentBase = public_program.cold_db(departmentSql)
        if departmentBase:
            departmentID = departmentBase[0]["DepartmentId"]
        else:
            return []
        # 查询部门表对应来源渠道数据
        if type(OrderSourceSKUID) == tuple:
            coldBaseSql = f"SELECT OrderSourceSKUID FROM aml_amazon_product_base_dep{departmentID} " \
                          f"WHERE OrderSourceID = {orderSourceID} AND IsHotData = 1 AND OrderSourceSKUID IN {OrderSourceSKUID};"
            coldBaseData = public_program.cold_db(coldBaseSql)
            return coldBaseData
        else:
            coldBaseSql = f"SELECT OrderSourceSKUID FROM aml_amazon_product_base_dep{departmentID} " \
                          f"WHERE OrderSourceID = {orderSourceID} AND IsHotData = 1 AND OrderSourceSKUID = {OrderSourceSKUID};"
            coldBaseData = public_program.cold_db(coldBaseSql)
            return coldBaseData

    # 查询大宽表数据
    def cheakErpBaseData(self, orderSourceID, OrderSourceSKUID):
        if type(OrderSourceSKUID) == tuple:
            erpSql = f"SELECT OrderSourceSKUID FROM RB_Amazon_product_Base(nolock) " \
                     f"WHERE OrderSourceID = {orderSourceID} AND OrderSourceSKUID IN {OrderSourceSKUID};"
            erpBaseData = public_program.erp_db(erpSql)
            return erpBaseData
        else:
            erpSql = f"SELECT OrderSourceSKUID FROM RB_Amazon_product_Base(nolock) " \
                     f"WHERE OrderSourceID = {orderSourceID} AND OrderSourceSKUID = {OrderSourceSKUID};"
            erpBaseData = public_program.erp_db(erpSql)
            return erpBaseData
